package com.manage.project.biz.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.project.biz.domain.BizShebei;
import com.manage.project.biz.service.IBizShebeiService;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

/**
 * 设备管理Controller
 *
 * @author liang

 */
@RestController
@RequestMapping("/biz/shebei")
public class BizShebeiController extends BaseController
{
    @Autowired
    private IBizShebeiService bizShebeiService;

    /**
     * 查询设备管理列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:shebei:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizShebei bizShebei)
    {
        startPage();
        List<BizShebei> list = bizShebeiService.selectBizShebeiList(bizShebei);
        return getDataTable(list);
    }

    /**
     * 导出设备管理列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:shebei:export')")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizShebei bizShebei)
    {
        List<BizShebei> list = bizShebeiService.selectBizShebeiList(bizShebei);
        ExcelUtil<BizShebei> util = new ExcelUtil<BizShebei>(BizShebei.class);
        return util.exportExcel(list, "设备管理数据");
    }

    /**
     * 获取设备管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:shebei:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizShebeiService.selectBizShebeiById(id));
    }

    /**
     * 新增设备管理
     */
//    @PreAuthorize("@ss.hasPermi('biz:shebei:add')")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizShebei bizShebei)
    {
        String id = bizShebei.getField1();
        if( bizShebeiService.getByFacilityId(id)!=null){
            return AjaxResult.error("当前设备已存在");
        }
        return toAjax(bizShebeiService.insertBizShebei(bizShebei));
    }

    /**
     * 修改设备管理
     */
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizShebei bizShebei)
    {
        String id = bizShebei.getField1();
        if( bizShebeiService.getByFacilityId(id)!=null){
            return AjaxResult.error("当前设备已存在");
        }
        return toAjax(bizShebeiService.updateBizShebei(bizShebei));
    }

    /**
     * 删除设备管理
     */
//    @PreAuthorize("@ss.hasPermi('biz:shebei:remove')")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizShebeiService.deleteBizShebeiByIds(ids));
    }
}
